package run;

import com.SpringBootApps;
import io.rsocket.metadata.WellKnownMimeType;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.messaging.rsocket.RSocketRequester;
import org.springframework.messaging.rsocket.RSocketStrategies;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
import utils.Utils;

@SpringBootTest(classes = {StartUpForRSocketClient.Dummy.class},
        webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class StartUpForRSocketClient {
    Object lock = new Object();
    @Autowired
    GenericApplicationContext context;

    private  RSocketRequester requester;

    // request ,
    @BeforeEach
    @SuppressWarnings("ConstantConditions")
    public  void setupOnce() {
        MimeType metadataMimeType = MimeTypeUtils.parseMimeType(
                WellKnownMimeType.MESSAGE_RSOCKET_COMPOSITE_METADATA.getString());

        requester = RSocketRequester.builder()
                .metadataMimeType(metadataMimeType)
                .rsocketStrategies(context.getBean(RSocketStrategies.class))
                .tcp("localhost", 7000);
    }
    @Test
    public void send(){
        // send the request .


    }
    @Test
    public void verify() throws InterruptedException {


        Utils.print(context);
        synchronized (lock) {
            lock.wait();
        }
    }

    @Import(value = {SpringBootApps.class,HelloController.class})
    @Configuration
    public static class Dummy {
    }

}
